package com.xjgzinfo.usdp.web.rest;

import com.xjgzinfo.usdp.AvueServer4jApp;
import com.xjgzinfo.usdp.config.TestSecurityConfiguration;
import com.xjgzinfo.usdp.domain.ImgAssets;
import com.xjgzinfo.usdp.repository.ImgAssetsRepository;
import com.xjgzinfo.usdp.service.ImgAssetsService;
import com.xjgzinfo.usdp.service.dto.ImgAssetsDTO;
import com.xjgzinfo.usdp.service.mapper.ImgAssetsMapper;
import com.xjgzinfo.usdp.service.dto.ImgAssetsCriteria;
import com.xjgzinfo.usdp.service.ImgAssetsQueryService;

import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.http.MediaType;
import org.springframework.security.test.context.support.WithMockUser;
import org.springframework.test.web.servlet.MockMvc;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.Base64Utils;
import javax.persistence.EntityManager;
import java.time.Instant;
import java.time.temporal.ChronoUnit;
import java.util.List;

import static org.assertj.core.api.Assertions.assertThat;
import static org.hamcrest.Matchers.hasItem;
import static org.springframework.security.test.web.servlet.request.SecurityMockMvcRequestPostProcessors.csrf;
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.*;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.*;

/**
 * Integration tests for the {@link ImgAssetsResource} REST controller.
 */
@SpringBootTest(classes = { AvueServer4jApp.class, TestSecurityConfiguration.class })
@AutoConfigureMockMvc
@WithMockUser
public class ImgAssetsResourceIT {

    private static final String DEFAULT_NAME = "AAAAAAAAAA";
    private static final String UPDATED_NAME = "BBBBBBBBBB";

    private static final String DEFAULT_TYPE = "AAAAAAAAAA";
    private static final String UPDATED_TYPE = "BBBBBBBBBB";

    private static final String DEFAULT_URL = "AAAAAAAAAA";
    private static final String UPDATED_URL = "BBBBBBBBBB";

    private static final String DEFAULT_CREATE_USER = "AAAAAAAAAA";
    private static final String UPDATED_CREATE_USER = "BBBBBBBBBB";

    private static final Instant DEFAULT_CREATE_DATE = Instant.ofEpochMilli(0L);
    private static final Instant UPDATED_CREATE_DATE = Instant.now().truncatedTo(ChronoUnit.MILLIS);

    private static final Boolean DEFAULT_IS_PUBLIC = false;
    private static final Boolean UPDATED_IS_PUBLIC = true;

    private static final Long DEFAULT_USER_ID = 1L;
    private static final Long UPDATED_USER_ID = 2L;
    private static final Long SMALLER_USER_ID = 1L - 1L;

    private static final Boolean DEFAULT_ENABLED = false;
    private static final Boolean UPDATED_ENABLED = true;

    @Autowired
    private ImgAssetsRepository imgAssetsRepository;

    @Autowired
    private ImgAssetsMapper imgAssetsMapper;

    @Autowired
    private ImgAssetsService imgAssetsService;

    @Autowired
    private ImgAssetsQueryService imgAssetsQueryService;

    @Autowired
    private EntityManager em;

    @Autowired
    private MockMvc restImgAssetsMockMvc;

    private ImgAssets imgAssets;

    /**
     * Create an entity for this test.
     *
     * This is a static method, as tests for other entities might also need it,
     * if they test an entity which requires the current entity.
     */
    public static ImgAssets createEntity(EntityManager em) {
        ImgAssets imgAssets = new ImgAssets()
            .name(DEFAULT_NAME)
            .type(DEFAULT_TYPE)
            .url(DEFAULT_URL)
            .createUser(DEFAULT_CREATE_USER)
            .createDate(DEFAULT_CREATE_DATE)
            .isPublic(DEFAULT_IS_PUBLIC)
            .userId(DEFAULT_USER_ID)
            .enabled(DEFAULT_ENABLED);
        return imgAssets;
    }
    /**
     * Create an updated entity for this test.
     *
     * This is a static method, as tests for other entities might also need it,
     * if they test an entity which requires the current entity.
     */
    public static ImgAssets createUpdatedEntity(EntityManager em) {
        ImgAssets imgAssets = new ImgAssets()
            .name(UPDATED_NAME)
            .type(UPDATED_TYPE)
            .url(UPDATED_URL)
            .createUser(UPDATED_CREATE_USER)
            .createDate(UPDATED_CREATE_DATE)
            .isPublic(UPDATED_IS_PUBLIC)
            .userId(UPDATED_USER_ID)
            .enabled(UPDATED_ENABLED);
        return imgAssets;
    }

    @BeforeEach
    public void initTest() {
        imgAssets = createEntity(em);
    }

    @Test
    @Transactional
    public void createImgAssets() throws Exception {
        int databaseSizeBeforeCreate = imgAssetsRepository.findAll().size();
        // Create the ImgAssets
        ImgAssetsDTO imgAssetsDTO = imgAssetsMapper.toDto(imgAssets);
        restImgAssetsMockMvc.perform(post("/api/img-assets").with(csrf())
            .contentType(MediaType.APPLICATION_JSON)
            .content(TestUtil.convertObjectToJsonBytes(imgAssetsDTO)))
            .andExpect(status().isCreated());

        // Validate the ImgAssets in the database
        List<ImgAssets> imgAssetsList = imgAssetsRepository.findAll();
        assertThat(imgAssetsList).hasSize(databaseSizeBeforeCreate + 1);
        ImgAssets testImgAssets = imgAssetsList.get(imgAssetsList.size() - 1);
        assertThat(testImgAssets.getName()).isEqualTo(DEFAULT_NAME);
        assertThat(testImgAssets.getType()).isEqualTo(DEFAULT_TYPE);
        assertThat(testImgAssets.getUrl()).isEqualTo(DEFAULT_URL);
        assertThat(testImgAssets.getCreateUser()).isEqualTo(DEFAULT_CREATE_USER);
        assertThat(testImgAssets.getCreateDate()).isEqualTo(DEFAULT_CREATE_DATE);
        assertThat(testImgAssets.isIsPublic()).isEqualTo(DEFAULT_IS_PUBLIC);
        assertThat(testImgAssets.getUserId()).isEqualTo(DEFAULT_USER_ID);
        assertThat(testImgAssets.isEnabled()).isEqualTo(DEFAULT_ENABLED);
    }

    @Test
    @Transactional
    public void createImgAssetsWithExistingId() throws Exception {
        int databaseSizeBeforeCreate = imgAssetsRepository.findAll().size();

        // Create the ImgAssets with an existing ID
        imgAssets.setId(1L);
        ImgAssetsDTO imgAssetsDTO = imgAssetsMapper.toDto(imgAssets);

        // An entity with an existing ID cannot be created, so this API call must fail
        restImgAssetsMockMvc.perform(post("/api/img-assets").with(csrf())
            .contentType(MediaType.APPLICATION_JSON)
            .content(TestUtil.convertObjectToJsonBytes(imgAssetsDTO)))
            .andExpect(status().isBadRequest());

        // Validate the ImgAssets in the database
        List<ImgAssets> imgAssetsList = imgAssetsRepository.findAll();
        assertThat(imgAssetsList).hasSize(databaseSizeBeforeCreate);
    }


    @Test
    @Transactional
    public void checkNameIsRequired() throws Exception {
        int databaseSizeBeforeTest = imgAssetsRepository.findAll().size();
        // set the field null
        imgAssets.setName(null);

        // Create the ImgAssets, which fails.
        ImgAssetsDTO imgAssetsDTO = imgAssetsMapper.toDto(imgAssets);


        restImgAssetsMockMvc.perform(post("/api/img-assets").with(csrf())
            .contentType(MediaType.APPLICATION_JSON)
            .content(TestUtil.convertObjectToJsonBytes(imgAssetsDTO)))
            .andExpect(status().isBadRequest());

        List<ImgAssets> imgAssetsList = imgAssetsRepository.findAll();
        assertThat(imgAssetsList).hasSize(databaseSizeBeforeTest);
    }

    @Test
    @Transactional
    public void checkTypeIsRequired() throws Exception {
        int databaseSizeBeforeTest = imgAssetsRepository.findAll().size();
        // set the field null
        imgAssets.setType(null);

        // Create the ImgAssets, which fails.
        ImgAssetsDTO imgAssetsDTO = imgAssetsMapper.toDto(imgAssets);


        restImgAssetsMockMvc.perform(post("/api/img-assets").with(csrf())
            .contentType(MediaType.APPLICATION_JSON)
            .content(TestUtil.convertObjectToJsonBytes(imgAssetsDTO)))
            .andExpect(status().isBadRequest());

        List<ImgAssets> imgAssetsList = imgAssetsRepository.findAll();
        assertThat(imgAssetsList).hasSize(databaseSizeBeforeTest);
    }

    @Test
    @Transactional
    public void getAllImgAssets() throws Exception {
        // Initialize the database
        imgAssetsRepository.saveAndFlush(imgAssets);

        // Get all the imgAssetsList
        restImgAssetsMockMvc.perform(get("/api/img-assets?sort=id,desc"))
            .andExpect(status().isOk())
            .andExpect(content().contentType(MediaType.APPLICATION_JSON_VALUE))
            .andExpect(jsonPath("$.[*].id").value(hasItem(imgAssets.getId().intValue())))
            .andExpect(jsonPath("$.[*].name").value(hasItem(DEFAULT_NAME)))
            .andExpect(jsonPath("$.[*].type").value(hasItem(DEFAULT_TYPE)))
            .andExpect(jsonPath("$.[*].url").value(hasItem(DEFAULT_URL.toString())))
            .andExpect(jsonPath("$.[*].createUser").value(hasItem(DEFAULT_CREATE_USER)))
            .andExpect(jsonPath("$.[*].createDate").value(hasItem(DEFAULT_CREATE_DATE.toString())))
            .andExpect(jsonPath("$.[*].isPublic").value(hasItem(DEFAULT_IS_PUBLIC.booleanValue())))
            .andExpect(jsonPath("$.[*].userId").value(hasItem(DEFAULT_USER_ID.intValue())))
            .andExpect(jsonPath("$.[*].enabled").value(hasItem(DEFAULT_ENABLED.booleanValue())));
    }
    
    @Test
    @Transactional
    public void getImgAssets() throws Exception {
        // Initialize the database
        imgAssetsRepository.saveAndFlush(imgAssets);

        // Get the imgAssets
        restImgAssetsMockMvc.perform(get("/api/img-assets/{id}", imgAssets.getId()))
            .andExpect(status().isOk())
            .andExpect(content().contentType(MediaType.APPLICATION_JSON_VALUE))
            .andExpect(jsonPath("$.id").value(imgAssets.getId().intValue()))
            .andExpect(jsonPath("$.name").value(DEFAULT_NAME))
            .andExpect(jsonPath("$.type").value(DEFAULT_TYPE))
            .andExpect(jsonPath("$.url").value(DEFAULT_URL.toString()))
            .andExpect(jsonPath("$.createUser").value(DEFAULT_CREATE_USER))
            .andExpect(jsonPath("$.createDate").value(DEFAULT_CREATE_DATE.toString()))
            .andExpect(jsonPath("$.isPublic").value(DEFAULT_IS_PUBLIC.booleanValue()))
            .andExpect(jsonPath("$.userId").value(DEFAULT_USER_ID.intValue()))
            .andExpect(jsonPath("$.enabled").value(DEFAULT_ENABLED.booleanValue()));
    }


    @Test
    @Transactional
    public void getImgAssetsByIdFiltering() throws Exception {
        // Initialize the database
        imgAssetsRepository.saveAndFlush(imgAssets);

        Long id = imgAssets.getId();

        defaultImgAssetsShouldBeFound("id.equals=" + id);
        defaultImgAssetsShouldNotBeFound("id.notEquals=" + id);

        defaultImgAssetsShouldBeFound("id.greaterThanOrEqual=" + id);
        defaultImgAssetsShouldNotBeFound("id.greaterThan=" + id);

        defaultImgAssetsShouldBeFound("id.lessThanOrEqual=" + id);
        defaultImgAssetsShouldNotBeFound("id.lessThan=" + id);
    }


    @Test
    @Transactional
    public void getAllImgAssetsByNameIsEqualToSomething() throws Exception {
        // Initialize the database
        imgAssetsRepository.saveAndFlush(imgAssets);

        // Get all the imgAssetsList where name equals to DEFAULT_NAME
        defaultImgAssetsShouldBeFound("name.equals=" + DEFAULT_NAME);

        // Get all the imgAssetsList where name equals to UPDATED_NAME
        defaultImgAssetsShouldNotBeFound("name.equals=" + UPDATED_NAME);
    }

    @Test
    @Transactional
    public void getAllImgAssetsByNameIsNotEqualToSomething() throws Exception {
        // Initialize the database
        imgAssetsRepository.saveAndFlush(imgAssets);

        // Get all the imgAssetsList where name not equals to DEFAULT_NAME
        defaultImgAssetsShouldNotBeFound("name.notEquals=" + DEFAULT_NAME);

        // Get all the imgAssetsList where name not equals to UPDATED_NAME
        defaultImgAssetsShouldBeFound("name.notEquals=" + UPDATED_NAME);
    }

    @Test
    @Transactional
    public void getAllImgAssetsByNameIsInShouldWork() throws Exception {
        // Initialize the database
        imgAssetsRepository.saveAndFlush(imgAssets);

        // Get all the imgAssetsList where name in DEFAULT_NAME or UPDATED_NAME
        defaultImgAssetsShouldBeFound("name.in=" + DEFAULT_NAME + "," + UPDATED_NAME);

        // Get all the imgAssetsList where name equals to UPDATED_NAME
        defaultImgAssetsShouldNotBeFound("name.in=" + UPDATED_NAME);
    }

    @Test
    @Transactional
    public void getAllImgAssetsByNameIsNullOrNotNull() throws Exception {
        // Initialize the database
        imgAssetsRepository.saveAndFlush(imgAssets);

        // Get all the imgAssetsList where name is not null
        defaultImgAssetsShouldBeFound("name.specified=true");

        // Get all the imgAssetsList where name is null
        defaultImgAssetsShouldNotBeFound("name.specified=false");
    }
                @Test
    @Transactional
    public void getAllImgAssetsByNameContainsSomething() throws Exception {
        // Initialize the database
        imgAssetsRepository.saveAndFlush(imgAssets);

        // Get all the imgAssetsList where name contains DEFAULT_NAME
        defaultImgAssetsShouldBeFound("name.contains=" + DEFAULT_NAME);

        // Get all the imgAssetsList where name contains UPDATED_NAME
        defaultImgAssetsShouldNotBeFound("name.contains=" + UPDATED_NAME);
    }

    @Test
    @Transactional
    public void getAllImgAssetsByNameNotContainsSomething() throws Exception {
        // Initialize the database
        imgAssetsRepository.saveAndFlush(imgAssets);

        // Get all the imgAssetsList where name does not contain DEFAULT_NAME
        defaultImgAssetsShouldNotBeFound("name.doesNotContain=" + DEFAULT_NAME);

        // Get all the imgAssetsList where name does not contain UPDATED_NAME
        defaultImgAssetsShouldBeFound("name.doesNotContain=" + UPDATED_NAME);
    }


    @Test
    @Transactional
    public void getAllImgAssetsByTypeIsEqualToSomething() throws Exception {
        // Initialize the database
        imgAssetsRepository.saveAndFlush(imgAssets);

        // Get all the imgAssetsList where type equals to DEFAULT_TYPE
        defaultImgAssetsShouldBeFound("type.equals=" + DEFAULT_TYPE);

        // Get all the imgAssetsList where type equals to UPDATED_TYPE
        defaultImgAssetsShouldNotBeFound("type.equals=" + UPDATED_TYPE);
    }

    @Test
    @Transactional
    public void getAllImgAssetsByTypeIsNotEqualToSomething() throws Exception {
        // Initialize the database
        imgAssetsRepository.saveAndFlush(imgAssets);

        // Get all the imgAssetsList where type not equals to DEFAULT_TYPE
        defaultImgAssetsShouldNotBeFound("type.notEquals=" + DEFAULT_TYPE);

        // Get all the imgAssetsList where type not equals to UPDATED_TYPE
        defaultImgAssetsShouldBeFound("type.notEquals=" + UPDATED_TYPE);
    }

    @Test
    @Transactional
    public void getAllImgAssetsByTypeIsInShouldWork() throws Exception {
        // Initialize the database
        imgAssetsRepository.saveAndFlush(imgAssets);

        // Get all the imgAssetsList where type in DEFAULT_TYPE or UPDATED_TYPE
        defaultImgAssetsShouldBeFound("type.in=" + DEFAULT_TYPE + "," + UPDATED_TYPE);

        // Get all the imgAssetsList where type equals to UPDATED_TYPE
        defaultImgAssetsShouldNotBeFound("type.in=" + UPDATED_TYPE);
    }

    @Test
    @Transactional
    public void getAllImgAssetsByTypeIsNullOrNotNull() throws Exception {
        // Initialize the database
        imgAssetsRepository.saveAndFlush(imgAssets);

        // Get all the imgAssetsList where type is not null
        defaultImgAssetsShouldBeFound("type.specified=true");

        // Get all the imgAssetsList where type is null
        defaultImgAssetsShouldNotBeFound("type.specified=false");
    }
                @Test
    @Transactional
    public void getAllImgAssetsByTypeContainsSomething() throws Exception {
        // Initialize the database
        imgAssetsRepository.saveAndFlush(imgAssets);

        // Get all the imgAssetsList where type contains DEFAULT_TYPE
        defaultImgAssetsShouldBeFound("type.contains=" + DEFAULT_TYPE);

        // Get all the imgAssetsList where type contains UPDATED_TYPE
        defaultImgAssetsShouldNotBeFound("type.contains=" + UPDATED_TYPE);
    }

    @Test
    @Transactional
    public void getAllImgAssetsByTypeNotContainsSomething() throws Exception {
        // Initialize the database
        imgAssetsRepository.saveAndFlush(imgAssets);

        // Get all the imgAssetsList where type does not contain DEFAULT_TYPE
        defaultImgAssetsShouldNotBeFound("type.doesNotContain=" + DEFAULT_TYPE);

        // Get all the imgAssetsList where type does not contain UPDATED_TYPE
        defaultImgAssetsShouldBeFound("type.doesNotContain=" + UPDATED_TYPE);
    }


    @Test
    @Transactional
    public void getAllImgAssetsByCreateUserIsEqualToSomething() throws Exception {
        // Initialize the database
        imgAssetsRepository.saveAndFlush(imgAssets);

        // Get all the imgAssetsList where createUser equals to DEFAULT_CREATE_USER
        defaultImgAssetsShouldBeFound("createUser.equals=" + DEFAULT_CREATE_USER);

        // Get all the imgAssetsList where createUser equals to UPDATED_CREATE_USER
        defaultImgAssetsShouldNotBeFound("createUser.equals=" + UPDATED_CREATE_USER);
    }

    @Test
    @Transactional
    public void getAllImgAssetsByCreateUserIsNotEqualToSomething() throws Exception {
        // Initialize the database
        imgAssetsRepository.saveAndFlush(imgAssets);

        // Get all the imgAssetsList where createUser not equals to DEFAULT_CREATE_USER
        defaultImgAssetsShouldNotBeFound("createUser.notEquals=" + DEFAULT_CREATE_USER);

        // Get all the imgAssetsList where createUser not equals to UPDATED_CREATE_USER
        defaultImgAssetsShouldBeFound("createUser.notEquals=" + UPDATED_CREATE_USER);
    }

    @Test
    @Transactional
    public void getAllImgAssetsByCreateUserIsInShouldWork() throws Exception {
        // Initialize the database
        imgAssetsRepository.saveAndFlush(imgAssets);

        // Get all the imgAssetsList where createUser in DEFAULT_CREATE_USER or UPDATED_CREATE_USER
        defaultImgAssetsShouldBeFound("createUser.in=" + DEFAULT_CREATE_USER + "," + UPDATED_CREATE_USER);

        // Get all the imgAssetsList where createUser equals to UPDATED_CREATE_USER
        defaultImgAssetsShouldNotBeFound("createUser.in=" + UPDATED_CREATE_USER);
    }

    @Test
    @Transactional
    public void getAllImgAssetsByCreateUserIsNullOrNotNull() throws Exception {
        // Initialize the database
        imgAssetsRepository.saveAndFlush(imgAssets);

        // Get all the imgAssetsList where createUser is not null
        defaultImgAssetsShouldBeFound("createUser.specified=true");

        // Get all the imgAssetsList where createUser is null
        defaultImgAssetsShouldNotBeFound("createUser.specified=false");
    }
                @Test
    @Transactional
    public void getAllImgAssetsByCreateUserContainsSomething() throws Exception {
        // Initialize the database
        imgAssetsRepository.saveAndFlush(imgAssets);

        // Get all the imgAssetsList where createUser contains DEFAULT_CREATE_USER
        defaultImgAssetsShouldBeFound("createUser.contains=" + DEFAULT_CREATE_USER);

        // Get all the imgAssetsList where createUser contains UPDATED_CREATE_USER
        defaultImgAssetsShouldNotBeFound("createUser.contains=" + UPDATED_CREATE_USER);
    }

    @Test
    @Transactional
    public void getAllImgAssetsByCreateUserNotContainsSomething() throws Exception {
        // Initialize the database
        imgAssetsRepository.saveAndFlush(imgAssets);

        // Get all the imgAssetsList where createUser does not contain DEFAULT_CREATE_USER
        defaultImgAssetsShouldNotBeFound("createUser.doesNotContain=" + DEFAULT_CREATE_USER);

        // Get all the imgAssetsList where createUser does not contain UPDATED_CREATE_USER
        defaultImgAssetsShouldBeFound("createUser.doesNotContain=" + UPDATED_CREATE_USER);
    }


    @Test
    @Transactional
    public void getAllImgAssetsByCreateDateIsEqualToSomething() throws Exception {
        // Initialize the database
        imgAssetsRepository.saveAndFlush(imgAssets);

        // Get all the imgAssetsList where createDate equals to DEFAULT_CREATE_DATE
        defaultImgAssetsShouldBeFound("createDate.equals=" + DEFAULT_CREATE_DATE);

        // Get all the imgAssetsList where createDate equals to UPDATED_CREATE_DATE
        defaultImgAssetsShouldNotBeFound("createDate.equals=" + UPDATED_CREATE_DATE);
    }

    @Test
    @Transactional
    public void getAllImgAssetsByCreateDateIsNotEqualToSomething() throws Exception {
        // Initialize the database
        imgAssetsRepository.saveAndFlush(imgAssets);

        // Get all the imgAssetsList where createDate not equals to DEFAULT_CREATE_DATE
        defaultImgAssetsShouldNotBeFound("createDate.notEquals=" + DEFAULT_CREATE_DATE);

        // Get all the imgAssetsList where createDate not equals to UPDATED_CREATE_DATE
        defaultImgAssetsShouldBeFound("createDate.notEquals=" + UPDATED_CREATE_DATE);
    }

    @Test
    @Transactional
    public void getAllImgAssetsByCreateDateIsInShouldWork() throws Exception {
        // Initialize the database
        imgAssetsRepository.saveAndFlush(imgAssets);

        // Get all the imgAssetsList where createDate in DEFAULT_CREATE_DATE or UPDATED_CREATE_DATE
        defaultImgAssetsShouldBeFound("createDate.in=" + DEFAULT_CREATE_DATE + "," + UPDATED_CREATE_DATE);

        // Get all the imgAssetsList where createDate equals to UPDATED_CREATE_DATE
        defaultImgAssetsShouldNotBeFound("createDate.in=" + UPDATED_CREATE_DATE);
    }

    @Test
    @Transactional
    public void getAllImgAssetsByCreateDateIsNullOrNotNull() throws Exception {
        // Initialize the database
        imgAssetsRepository.saveAndFlush(imgAssets);

        // Get all the imgAssetsList where createDate is not null
        defaultImgAssetsShouldBeFound("createDate.specified=true");

        // Get all the imgAssetsList where createDate is null
        defaultImgAssetsShouldNotBeFound("createDate.specified=false");
    }

    @Test
    @Transactional
    public void getAllImgAssetsByIsPublicIsEqualToSomething() throws Exception {
        // Initialize the database
        imgAssetsRepository.saveAndFlush(imgAssets);

        // Get all the imgAssetsList where isPublic equals to DEFAULT_IS_PUBLIC
        defaultImgAssetsShouldBeFound("isPublic.equals=" + DEFAULT_IS_PUBLIC);

        // Get all the imgAssetsList where isPublic equals to UPDATED_IS_PUBLIC
        defaultImgAssetsShouldNotBeFound("isPublic.equals=" + UPDATED_IS_PUBLIC);
    }

    @Test
    @Transactional
    public void getAllImgAssetsByIsPublicIsNotEqualToSomething() throws Exception {
        // Initialize the database
        imgAssetsRepository.saveAndFlush(imgAssets);

        // Get all the imgAssetsList where isPublic not equals to DEFAULT_IS_PUBLIC
        defaultImgAssetsShouldNotBeFound("isPublic.notEquals=" + DEFAULT_IS_PUBLIC);

        // Get all the imgAssetsList where isPublic not equals to UPDATED_IS_PUBLIC
        defaultImgAssetsShouldBeFound("isPublic.notEquals=" + UPDATED_IS_PUBLIC);
    }

    @Test
    @Transactional
    public void getAllImgAssetsByIsPublicIsInShouldWork() throws Exception {
        // Initialize the database
        imgAssetsRepository.saveAndFlush(imgAssets);

        // Get all the imgAssetsList where isPublic in DEFAULT_IS_PUBLIC or UPDATED_IS_PUBLIC
        defaultImgAssetsShouldBeFound("isPublic.in=" + DEFAULT_IS_PUBLIC + "," + UPDATED_IS_PUBLIC);

        // Get all the imgAssetsList where isPublic equals to UPDATED_IS_PUBLIC
        defaultImgAssetsShouldNotBeFound("isPublic.in=" + UPDATED_IS_PUBLIC);
    }

    @Test
    @Transactional
    public void getAllImgAssetsByIsPublicIsNullOrNotNull() throws Exception {
        // Initialize the database
        imgAssetsRepository.saveAndFlush(imgAssets);

        // Get all the imgAssetsList where isPublic is not null
        defaultImgAssetsShouldBeFound("isPublic.specified=true");

        // Get all the imgAssetsList where isPublic is null
        defaultImgAssetsShouldNotBeFound("isPublic.specified=false");
    }

    @Test
    @Transactional
    public void getAllImgAssetsByUserIdIsEqualToSomething() throws Exception {
        // Initialize the database
        imgAssetsRepository.saveAndFlush(imgAssets);

        // Get all the imgAssetsList where userId equals to DEFAULT_USER_ID
        defaultImgAssetsShouldBeFound("userId.equals=" + DEFAULT_USER_ID);

        // Get all the imgAssetsList where userId equals to UPDATED_USER_ID
        defaultImgAssetsShouldNotBeFound("userId.equals=" + UPDATED_USER_ID);
    }

    @Test
    @Transactional
    public void getAllImgAssetsByUserIdIsNotEqualToSomething() throws Exception {
        // Initialize the database
        imgAssetsRepository.saveAndFlush(imgAssets);

        // Get all the imgAssetsList where userId not equals to DEFAULT_USER_ID
        defaultImgAssetsShouldNotBeFound("userId.notEquals=" + DEFAULT_USER_ID);

        // Get all the imgAssetsList where userId not equals to UPDATED_USER_ID
        defaultImgAssetsShouldBeFound("userId.notEquals=" + UPDATED_USER_ID);
    }

    @Test
    @Transactional
    public void getAllImgAssetsByUserIdIsInShouldWork() throws Exception {
        // Initialize the database
        imgAssetsRepository.saveAndFlush(imgAssets);

        // Get all the imgAssetsList where userId in DEFAULT_USER_ID or UPDATED_USER_ID
        defaultImgAssetsShouldBeFound("userId.in=" + DEFAULT_USER_ID + "," + UPDATED_USER_ID);

        // Get all the imgAssetsList where userId equals to UPDATED_USER_ID
        defaultImgAssetsShouldNotBeFound("userId.in=" + UPDATED_USER_ID);
    }

    @Test
    @Transactional
    public void getAllImgAssetsByUserIdIsNullOrNotNull() throws Exception {
        // Initialize the database
        imgAssetsRepository.saveAndFlush(imgAssets);

        // Get all the imgAssetsList where userId is not null
        defaultImgAssetsShouldBeFound("userId.specified=true");

        // Get all the imgAssetsList where userId is null
        defaultImgAssetsShouldNotBeFound("userId.specified=false");
    }

    @Test
    @Transactional
    public void getAllImgAssetsByUserIdIsGreaterThanOrEqualToSomething() throws Exception {
        // Initialize the database
        imgAssetsRepository.saveAndFlush(imgAssets);

        // Get all the imgAssetsList where userId is greater than or equal to DEFAULT_USER_ID
        defaultImgAssetsShouldBeFound("userId.greaterThanOrEqual=" + DEFAULT_USER_ID);

        // Get all the imgAssetsList where userId is greater than or equal to UPDATED_USER_ID
        defaultImgAssetsShouldNotBeFound("userId.greaterThanOrEqual=" + UPDATED_USER_ID);
    }

    @Test
    @Transactional
    public void getAllImgAssetsByUserIdIsLessThanOrEqualToSomething() throws Exception {
        // Initialize the database
        imgAssetsRepository.saveAndFlush(imgAssets);

        // Get all the imgAssetsList where userId is less than or equal to DEFAULT_USER_ID
        defaultImgAssetsShouldBeFound("userId.lessThanOrEqual=" + DEFAULT_USER_ID);

        // Get all the imgAssetsList where userId is less than or equal to SMALLER_USER_ID
        defaultImgAssetsShouldNotBeFound("userId.lessThanOrEqual=" + SMALLER_USER_ID);
    }

    @Test
    @Transactional
    public void getAllImgAssetsByUserIdIsLessThanSomething() throws Exception {
        // Initialize the database
        imgAssetsRepository.saveAndFlush(imgAssets);

        // Get all the imgAssetsList where userId is less than DEFAULT_USER_ID
        defaultImgAssetsShouldNotBeFound("userId.lessThan=" + DEFAULT_USER_ID);

        // Get all the imgAssetsList where userId is less than UPDATED_USER_ID
        defaultImgAssetsShouldBeFound("userId.lessThan=" + UPDATED_USER_ID);
    }

    @Test
    @Transactional
    public void getAllImgAssetsByUserIdIsGreaterThanSomething() throws Exception {
        // Initialize the database
        imgAssetsRepository.saveAndFlush(imgAssets);

        // Get all the imgAssetsList where userId is greater than DEFAULT_USER_ID
        defaultImgAssetsShouldNotBeFound("userId.greaterThan=" + DEFAULT_USER_ID);

        // Get all the imgAssetsList where userId is greater than SMALLER_USER_ID
        defaultImgAssetsShouldBeFound("userId.greaterThan=" + SMALLER_USER_ID);
    }


    @Test
    @Transactional
    public void getAllImgAssetsByEnabledIsEqualToSomething() throws Exception {
        // Initialize the database
        imgAssetsRepository.saveAndFlush(imgAssets);

        // Get all the imgAssetsList where enabled equals to DEFAULT_ENABLED
        defaultImgAssetsShouldBeFound("enabled.equals=" + DEFAULT_ENABLED);

        // Get all the imgAssetsList where enabled equals to UPDATED_ENABLED
        defaultImgAssetsShouldNotBeFound("enabled.equals=" + UPDATED_ENABLED);
    }

    @Test
    @Transactional
    public void getAllImgAssetsByEnabledIsNotEqualToSomething() throws Exception {
        // Initialize the database
        imgAssetsRepository.saveAndFlush(imgAssets);

        // Get all the imgAssetsList where enabled not equals to DEFAULT_ENABLED
        defaultImgAssetsShouldNotBeFound("enabled.notEquals=" + DEFAULT_ENABLED);

        // Get all the imgAssetsList where enabled not equals to UPDATED_ENABLED
        defaultImgAssetsShouldBeFound("enabled.notEquals=" + UPDATED_ENABLED);
    }

    @Test
    @Transactional
    public void getAllImgAssetsByEnabledIsInShouldWork() throws Exception {
        // Initialize the database
        imgAssetsRepository.saveAndFlush(imgAssets);

        // Get all the imgAssetsList where enabled in DEFAULT_ENABLED or UPDATED_ENABLED
        defaultImgAssetsShouldBeFound("enabled.in=" + DEFAULT_ENABLED + "," + UPDATED_ENABLED);

        // Get all the imgAssetsList where enabled equals to UPDATED_ENABLED
        defaultImgAssetsShouldNotBeFound("enabled.in=" + UPDATED_ENABLED);
    }

    @Test
    @Transactional
    public void getAllImgAssetsByEnabledIsNullOrNotNull() throws Exception {
        // Initialize the database
        imgAssetsRepository.saveAndFlush(imgAssets);

        // Get all the imgAssetsList where enabled is not null
        defaultImgAssetsShouldBeFound("enabled.specified=true");

        // Get all the imgAssetsList where enabled is null
        defaultImgAssetsShouldNotBeFound("enabled.specified=false");
    }
    /**
     * Executes the search, and checks that the default entity is returned.
     */
    private void defaultImgAssetsShouldBeFound(String filter) throws Exception {
        restImgAssetsMockMvc.perform(get("/api/img-assets?sort=id,desc&" + filter))
            .andExpect(status().isOk())
            .andExpect(content().contentType(MediaType.APPLICATION_JSON_VALUE))
            .andExpect(jsonPath("$.[*].id").value(hasItem(imgAssets.getId().intValue())))
            .andExpect(jsonPath("$.[*].name").value(hasItem(DEFAULT_NAME)))
            .andExpect(jsonPath("$.[*].type").value(hasItem(DEFAULT_TYPE)))
            .andExpect(jsonPath("$.[*].url").value(hasItem(DEFAULT_URL.toString())))
            .andExpect(jsonPath("$.[*].createUser").value(hasItem(DEFAULT_CREATE_USER)))
            .andExpect(jsonPath("$.[*].createDate").value(hasItem(DEFAULT_CREATE_DATE.toString())))
            .andExpect(jsonPath("$.[*].isPublic").value(hasItem(DEFAULT_IS_PUBLIC.booleanValue())))
            .andExpect(jsonPath("$.[*].userId").value(hasItem(DEFAULT_USER_ID.intValue())))
            .andExpect(jsonPath("$.[*].enabled").value(hasItem(DEFAULT_ENABLED.booleanValue())));

        // Check, that the count call also returns 1
        restImgAssetsMockMvc.perform(get("/api/img-assets/count?sort=id,desc&" + filter))
            .andExpect(status().isOk())
            .andExpect(content().contentType(MediaType.APPLICATION_JSON_VALUE))
            .andExpect(content().string("1"));
    }

    /**
     * Executes the search, and checks that the default entity is not returned.
     */
    private void defaultImgAssetsShouldNotBeFound(String filter) throws Exception {
        restImgAssetsMockMvc.perform(get("/api/img-assets?sort=id,desc&" + filter))
            .andExpect(status().isOk())
            .andExpect(content().contentType(MediaType.APPLICATION_JSON_VALUE))
            .andExpect(jsonPath("$").isArray())
            .andExpect(jsonPath("$").isEmpty());

        // Check, that the count call also returns 0
        restImgAssetsMockMvc.perform(get("/api/img-assets/count?sort=id,desc&" + filter))
            .andExpect(status().isOk())
            .andExpect(content().contentType(MediaType.APPLICATION_JSON_VALUE))
            .andExpect(content().string("0"));
    }

    @Test
    @Transactional
    public void getNonExistingImgAssets() throws Exception {
        // Get the imgAssets
        restImgAssetsMockMvc.perform(get("/api/img-assets/{id}", Long.MAX_VALUE))
            .andExpect(status().isNotFound());
    }

    @Test
    @Transactional
    public void updateImgAssets() throws Exception {
        // Initialize the database
        imgAssetsRepository.saveAndFlush(imgAssets);

        int databaseSizeBeforeUpdate = imgAssetsRepository.findAll().size();

        // Update the imgAssets
        ImgAssets updatedImgAssets = imgAssetsRepository.findById(imgAssets.getId()).get();
        // Disconnect from session so that the updates on updatedImgAssets are not directly saved in db
        em.detach(updatedImgAssets);
        updatedImgAssets
            .name(UPDATED_NAME)
            .type(UPDATED_TYPE)
            .url(UPDATED_URL)
            .createUser(UPDATED_CREATE_USER)
            .createDate(UPDATED_CREATE_DATE)
            .isPublic(UPDATED_IS_PUBLIC)
            .userId(UPDATED_USER_ID)
            .enabled(UPDATED_ENABLED);
        ImgAssetsDTO imgAssetsDTO = imgAssetsMapper.toDto(updatedImgAssets);

        restImgAssetsMockMvc.perform(put("/api/img-assets").with(csrf())
            .contentType(MediaType.APPLICATION_JSON)
            .content(TestUtil.convertObjectToJsonBytes(imgAssetsDTO)))
            .andExpect(status().isOk());

        // Validate the ImgAssets in the database
        List<ImgAssets> imgAssetsList = imgAssetsRepository.findAll();
        assertThat(imgAssetsList).hasSize(databaseSizeBeforeUpdate);
        ImgAssets testImgAssets = imgAssetsList.get(imgAssetsList.size() - 1);
        assertThat(testImgAssets.getName()).isEqualTo(UPDATED_NAME);
        assertThat(testImgAssets.getType()).isEqualTo(UPDATED_TYPE);
        assertThat(testImgAssets.getUrl()).isEqualTo(UPDATED_URL);
        assertThat(testImgAssets.getCreateUser()).isEqualTo(UPDATED_CREATE_USER);
        assertThat(testImgAssets.getCreateDate()).isEqualTo(UPDATED_CREATE_DATE);
        assertThat(testImgAssets.isIsPublic()).isEqualTo(UPDATED_IS_PUBLIC);
        assertThat(testImgAssets.getUserId()).isEqualTo(UPDATED_USER_ID);
        assertThat(testImgAssets.isEnabled()).isEqualTo(UPDATED_ENABLED);
    }

    @Test
    @Transactional
    public void updateNonExistingImgAssets() throws Exception {
        int databaseSizeBeforeUpdate = imgAssetsRepository.findAll().size();

        // Create the ImgAssets
        ImgAssetsDTO imgAssetsDTO = imgAssetsMapper.toDto(imgAssets);

        // If the entity doesn't have an ID, it will throw BadRequestAlertException
        restImgAssetsMockMvc.perform(put("/api/img-assets").with(csrf())
            .contentType(MediaType.APPLICATION_JSON)
            .content(TestUtil.convertObjectToJsonBytes(imgAssetsDTO)))
            .andExpect(status().isBadRequest());

        // Validate the ImgAssets in the database
        List<ImgAssets> imgAssetsList = imgAssetsRepository.findAll();
        assertThat(imgAssetsList).hasSize(databaseSizeBeforeUpdate);
    }

    @Test
    @Transactional
    public void deleteImgAssets() throws Exception {
        // Initialize the database
        imgAssetsRepository.saveAndFlush(imgAssets);

        int databaseSizeBeforeDelete = imgAssetsRepository.findAll().size();

        // Delete the imgAssets
        restImgAssetsMockMvc.perform(delete("/api/img-assets/{id}", imgAssets.getId()).with(csrf())
            .accept(MediaType.APPLICATION_JSON))
            .andExpect(status().isNoContent());

        // Validate the database contains one less item
        List<ImgAssets> imgAssetsList = imgAssetsRepository.findAll();
        assertThat(imgAssetsList).hasSize(databaseSizeBeforeDelete - 1);
    }
}
